#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QNetworkInterface>
#include <QMainWindow>
#include <QString>
#include <QDebug>
#include <QAction>
#include <QScrollBar>
#include <QVector>
#include <QFileDialog>
#include <QListWidgetItem>
#include <QStringList>
#include <QMutex>
#include <QDir>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QStack>
#include <QFont>
#include "vfoldercreatedialog.h"
#include "server.h"
#include "virtualfssession.h"
#include "dbusconnector.h"
#include "settings.h"
#include "renamedialog.h"
#include "statusbarinformer.h"
#include "animatetrayicon.h"
#include "settingsdialog.h"
#include "actionselectdialog.h"


namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(DBusConnector *dbus_c, QWidget *parent = 0);
    ~MainWindow();

    void closeEvent(QCloseEvent *e);

    void setupIcons();
    void buildBar();
    void shareFile(const QString & dir, const QString & file);
    void shareFolder(const QString &);
    void setListItemStyle(QListWidgetItem *item, bool hidden, bool dir);
    void flushVfsList(VirtualFsObject *vfs);
    void refreshCurrentFolder(VirtualFsObject *vfso = 0);
    void restoreSessionFromFile(const QString &f);
    bool jumpToFolder(VirtualFsObject *obj, const QString & f = "/" );
    QString currentFolder();
    VirtualFsObject *virtualFsObjectByNameInCurDir(QString patch);

    static inline Settings & settings() {
        return _settings;
    }

    void readSettings();

    static void async_kill(ClientsDataBase *base, QStringList *list);
    static void ServerAbortAndExit(MainWindow *window);
    static Settings _settings;

private:
    void setupTrayActions();
    void dbusSetup();
    void setupShortCuts();

public slots:
    void shareNewObjects(QStringList );
    void updateBar();
    void disconnectAllAndExit();
    void forceDisconnectAllAndExit();
    void close_event_hide();
    void close_event_close();

private slots:
    void start_server();
    void stop_server();
    void appendLog(const QString & text, uint color);
    void addClient(ClientThread *t);
    void removeClient(const QString & ip);
    void letsShareFile();
    void letsCreateFolder();
    void letsShareFolder();
    void on_shared_listWidget_itemDoubleClicked(QListWidgetItem *item);
    void on_back_pushButton_clicked();
    void vfolderCreate(const QString &);
    void contextOpenPressed();
    void contextCopyAddressPressed();
    void contextDeletePressed();
    void contextInfoPressed();
    void contextSetInvisible();
    void contextSetVisible();
    void on_shared_listWidget_customContextMenuRequested(const QPoint &pos);
    void CloseWindow();
    void on_exit_action_triggered();
    void systrayClicked(QSystemTrayIcon::ActivationReason );
    void copyAddressToClipboard();
    void contextRenamePressed();
    void on_actionAbout_triggered();
    void hideToTray();
    void fileHasBeenRenamed(QString, QString);
    void on_clients_treeWidget_customContextMenuRequested(const QPoint &pos);
    void contextClientInfo();
    void contextClientKick();
    void contextLogCopy();
    void on_actionSave_triggered();
    void on_actionRestore_triggered();
    void on_actionRestore_and_append_triggered();
    void on_way_lineEdit_returnPressed();
    void animateTrayUpload();
    void trayQuiescentState();
    void setDefaultTrayIcon();
    void on_actionKik_all_triggered();
    void on_actionClear_triggered();
    void on_actionLock_add_triggered();
    void on_actionForce_disconnect_all_triggered();
    void on_actionSettings_triggered();
    void menuConnectionLogShow();
    void on_log_listWidget_customContextMenuRequested(const QPoint &pos);
    void on_ip_comboBox_editTextChanged(const QString &arg1);

    void on_ip_comboBox_activated(int index);

private:
    Ui::MainWindow *ui;
    Server *server;
    QVector <QString> clients_base;
    VirtualFsObject *vfs_c;
    QMutex logmutex, clientmutex, filesmutex;
    bool killer_block, _no_close,
         exit_on_emty_client_list,
         dont_ask_again;
    char ip_line_custom_text;
    QSystemTrayIcon *systray;
    QMenu *trayIconMenu;
    VirtualFsSession fs_session;
    QStack <QString> ustack;

    DBusConnector *_dbus_c;
    StatusBarInformer *barInformer;
    AnimateTrayIcon *trayAnimation;
    AnimationObject uploadAnimation;

    QIcon defaultTrayIcon;
    ActionSelectDialog *as_dialog;

    struct {
        QIcon edit_copy;
        QIcon edit_del;
        QIcon edit_rename;
        QIcon doc_open_folder;
        QIcon user_visible, user_invisible;
        QIcon info;
    }icons;
};

#endif // MAINWINDOW_H
